package com.sky.config;

import com.sky.properties.AliOssProperties;
import com.sky.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class OssConfiguration {

    @Autowired
    private AliOssProperties aliOssProperties;

    @Bean//为了确保在程序运行时自动创建AliOssUtil对象并进行赋值，把他交给spring的ioc容器管理
    @ConditionalOnMissingBean//确保如果没有在创建，确保只有一个AliOssUtil的bean
    public AliOssUtil getAliOss() {
        log.info("开始创建阿里云文件上传工具类：{}", aliOssProperties);
        AliOssUtil aliOssUtil = new AliOssUtil();
        BeanUtils.copyProperties(aliOssProperties,aliOssUtil);
        return aliOssUtil;
    }
}
